package com.xiongwei.factory;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 一个披萨项目：要求便于种类扩展，便于维护
 * 1.披萨种类：GreekPizza, CheesePizza等
 * 2.制作过程：prepare,bake,cut,box
 * 3.完成披萨订购
 * @author xiongwei
 */
public class OrderPizza {

    /**
     * 优点：好理解，易操作
     * 缺点：违反了ocp原则，添加新的pizza类时要修改代码
     */
    public OrderPizza() {
        Pizza pizza = null;
        String orderType;

        do {
            orderType = getType();
            switch (orderType) {
                case "greek":
                    pizza = new GreekPizza();
                    pizza.setName("希腊披萨");
                    break;
                case "cheese":
                    pizza = new CheesePizza();
                    pizza.setName("奶酪披萨");
                    break;
                case "pepper":
                    pizza = new PepperPizza();
                    pizza.setName("胡椒披萨");
                    break;
                default:
                    System.out.println("披萨种类错误，请重新输入");
                    break;
            }
        } while (true);

    }

    /**
     * 客户键入pizza种类
     * @return
     */
    public String getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入pizza种类");
        String s = null;
        try {
            s = bufferedReader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return s;
    }
}
